home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / handson / handson.exe / SETUNIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-02-02  |  1.4 KB  |  54 lines

  1. unit Setunit;
  2. { PC Plus simple Delphi sample program. Illustrates the use of Sets
  3.   with integers and chars }
  4. interface
  5.  
  6. uses
  7.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  8.   Forms, Dialogs, StdCtrls;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     ListBox1: TListBox;
  13.     Button1: TButton;
  14.     procedure Button1Click(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.DFM}
  27.  
  28. procedure TForm1.Button1Click(Sender: TObject);
  29. type { the type MyNumbers defines integers between 0 and 100 }
  30.   MyNumbers = 1..100;
  31. const
  32.      { the const, Digits, defines a set (effectively a 'subset') of
  33.        MyNumbers between 1 and 10 }
  34.   Digits : set of MyNumbers = [1..10];
  35.      { UpCaseLetters defines a set of chars from 'A' to 'Z'    }
  36.   UpCaseLetters : set of char = ['A'..'Z'];
  37. begin
  38.   { Beware: set constants aren't as constant as they seem. Try
  39.     uncommenting this line and re-running the program. }
  40. {   Digits := [1..20];    }
  41.   { test for set membership using 'in' }
  42.   if 'A' in UpCaseLetters then
  43.      ListBox1.Items.Add('Yes - A is in UpCaseLetters')
  44.   else
  45.      ListBox1.Items.Add('No - A is not in UpCaseLetters');
  46.   if 11 in Digits then
  47.      ListBox1.Items.Add('Yes - 11 is in Digits')
  48.   else
  49.      ListBox1.Items.Add('No - 11 is not in Digits');
  50.  
  51. end;
  52.                        
  53. end.
  54.